package com.seawaterbt.springbootshiro.result;

import com.seawaterbt.springbootshiro.enums.ErrorCode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * 2018/7/24
 */
@ApiModel("返回数据")
@Data
public class ResultData {

    @ApiModelProperty("返回编码")
    private Integer code;

    @ApiModelProperty("提示信息")
    private String msg;

    @ApiModelProperty("返回数据")
    private Object data;

    @ApiModelProperty("记录总数")
    private Long count;

    public ResultData() {
    }

    public ResultData(Integer code, String msg, Object data, Long count) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.count = count;
    }

    public static ResultData ok(){
        return new ResultData(ErrorCode.SERVER_OK.getCode(),ErrorCode.SERVER_OK.getMessage(),null,null);
    }

    public static ResultData ok(ErrorCode errorCode){
        return new ResultData(errorCode.getCode(),errorCode.getMessage(),null,null);
    }

    public static ResultData ok(Integer code,String message){
        return new ResultData(code,message,null,null);
    }

    public static ResultData ok(Object data){
        return new ResultData(ErrorCode.SERVER_OK.getCode(),ErrorCode.SERVER_OK.getMessage(),data,null);
    }

    public static ResultData ok(Object data,Long count){
        return new ResultData(ErrorCode.SERVER_OK.getCode(),ErrorCode.SERVER_OK.getMessage(),data,count);
    }

    public static ResultData ok(Integer code,String message,Object data,Long count){
        return new ResultData(code,message,data,count);
    }


    public static ResultData failure(){
        return new ResultData(ErrorCode.SERVER_SYSTEM_ERROR.getCode(),ErrorCode.SERVER_SYSTEM_ERROR.getMessage(),null,null);
    }

    public static ResultData failure(Integer code,String message){
        return new ResultData(code,message,null,null);
    }

    public static ResultData failure(ErrorCode errorCode){
        return new ResultData(errorCode.getCode(),errorCode.getMessage(),null,null);
    }
}
